//
//  NewTableViewCell.m
//  艾听歌
//
//  Created by dllo on 16/5/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NewTableViewCell.h"
#import "NewCollectionViewCell.h"

#define NewCELL @"CELL"

@interface NewTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;

@end

@implementation NewTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollectionView];
    }
    return self;
}
- (void)createCollectionView
{
    
    self.data = [NSMutableArray array];
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 3, self.contentView.frame.size.height - 10);
    self.flowLayout.minimumInteritemSpacing = 0.5;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:self.flowLayout];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.contentView addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.collectionView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9C9C9C);

    [self.collectionView registerClass:[NewCollectionViewCell class] forCellWithReuseIdentifier:NewCELL];

}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.collectionView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    self.flowLayout.itemSize = CGSizeMake(self.contentView.frame.size.width / 3 - 2  , self.contentView.frame.size.height);
    
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return self.data.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NewCELL forIndexPath:indexPath];
   
    cell.backgroundColor = [UIColor clearColor];
    cell.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x9C9C9C);

    cell.NewCellModel = [self.data objectAtIndex:indexPath.row];
    
    
    return cell;
}

- (void)setNewMusicModel:(MusicModel *)NewMusicModel
{
    _NewMusicModel = NewMusicModel;
    self.data = [NSMutableArray arrayWithArray:_NewMusicModel.data];
    [self.collectionView reloadData];
}







@end
